home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / src / emog.lha / scanner.e < prev    next >
Encoding:
Text File  |  2000-03-07  |  3.2 KB  |  101 lines

  1. /* -- ----------------------------------------------------- -- *
  2.  * -- Name........: scanner.e                               -- *
  3.  * -- Description.: This module takes over the lexical part -- *
  4.  * --               of the conversion process. It uses an   -- *
  5.  * --               external binary generated with "flex".  -- *
  6.  * -- Author......: Daniel Kasmeroglu                       -- *
  7.  * -- E-Mail......: raptor@cs.tu-berlin.de                  -- *
  8.  * --               daniel.kasmeroglu@daimlerchrysler.com   -- *
  9.  * -- Date........: 05-Mar-00                               -- *
  10.  * -- Version.....: 0.1                                     -- *
  11.  * -- ----------------------------------------------------- -- */
  12.  
  13. /* -- ----------------------------------------------------- -- *
  14.  * --                          Options                      -- *
  15.  * -- ----------------------------------------------------- -- */
  16.  
  17. OPT MODULE
  18.  
  19.  
  20. /* -- ----------------------------------------------------- -- *
  21.  * --                          Modules                      -- *
  22.  * -- ----------------------------------------------------- -- */
  23.  
  24. MODULE '*tools'
  25.  
  26.  
  27. /* -- ----------------------------------------------------- -- *
  28.  * --                         Functions                     -- *
  29.  * -- ----------------------------------------------------- -- */
  30.  
  31. ->> PROC scan()
  32. ->
  33. -> SPEC   scan( source, dest )
  34. -> DESC   Scans the sourcefile {source} and stores it under a
  35. ->        temporary path. Under {dest} a writable buffer must
  36. ->        be supplied, since the temporary destination will be
  37. ->        found here.
  38. -> PRE    {source} : Path of the C-Header file
  39. ->        {dest}   : A valid buffer for keeping the
  40. ->                   path of the temporary file
  41. -> POST   {dest}   : Path of a file containing a list of tokens.
  42. ->
  43. EXPORT PROC scan( sca_source, sca_scanned )
  44. DEF sca_command [20] : STRING
  45. DEF sca_input, sca_output, sca_res
  46.  
  47.   -> Get a temporary file for storing our binary
  48.   -> and write the executable.
  49.   getTempFile( sca_command )
  50.   IF writeFile( sca_command, {binary}, {endofbinary} - {binary} ) = FALSE
  51.     Raise( "SCAN" )
  52.   ENDIF
  53.  
  54.   -> Get a temporary file for our destination
  55.   getTempFile( sca_scanned )
  56.  
  57.   -> Open source and destination
  58.   sca_input  := Open( sca_source  , OLDFILE )
  59.   sca_output := Open( sca_scanned , NEWFILE )
  60.   IF (sca_input = NIL) OR (sca_output = NIL)
  61.  
  62.     -> Damn, something went wrong
  63.     IF sca_input  <> NIL THEN Close( sca_input  )
  64.     IF sca_output <> NIL THEN Close( sca_output )
  65.     DeleteFile( sca_command )
  66.     Raise( "SCAN" )
  67.  
  68.   ENDIF
  69.  
  70.   -> Small message
  71.   WriteF( 'Scanning...\n' )
  72.  
  73.   -> The binary will be executed with proper
  74.   -> input and output
  75.   sca_res := Execute( sca_command, sca_input, sca_output )
  76.   Close( sca_input  )
  77.   Close( sca_output )
  78.  
  79.   DeleteFile( sca_command )
  80.  
  81.   IF sca_res = FALSE
  82.     -> Problem occured during scanning, so delete
  83.     -> the destination as it may contain invalid
  84.     -> data.
  85.     DeleteFile( sca_scanned )
  86.     Raise( "SCAN" )
  87.   ENDIF
  88.  
  89. ENDPROC
  90. -><
  91.  
  92.  
  93. /* -- ----------------------------------------------------- -- *
  94.  * --                            Data                       -- *
  95.  * -- ----------------------------------------------------- -- */
  96.  
  97. binary:
  98. INCBIN 'scanner'
  99. endofbinary:
  100.  
  101.